package com.hrt.datasender.process.heartbeat.hj212;

import java.text.SimpleDateFormat;
import java.util.Date;

import com.hrt.datasender.datadao.model.BcSendPlatformModel;
import com.hrt.datasender.datadao.service.BCSiteService;
import com.hrt.datasender.process.strategy.hj212.util.CRCUtil;

public class Heartbeat212 extends HeartbeatBase {
    private final int interval = 30;
    private final int dataLengthFormat = 4;

    public String getData(BcSendPlatformModel platform) {

        String heartBeatData = getCommandPacket(platform);

        return heartBeatData;
    }

    public String getCommandPacket(BcSendPlatformModel platform) {

        SimpleDateFormat sf = new SimpleDateFormat("yyyyMMddHHmmsss");
        StringBuilder strBuilder = new StringBuilder();

        strBuilder.append("QN=" + sf.format(new Date()) + ";");
        strBuilder.append("ST=" + BCSiteService.getInstance().getModel().getSystemType() + ";");
        strBuilder.append("CN=9021;");
        strBuilder.append("PW=123456;");
        strBuilder.append("MN=" + platform.getMn() + ";");

        String crcStr = CRCUtil.calcCRC(strBuilder.toString());

        String dataLength = strBuilder.length() + "";
        while (dataLength.length() < dataLengthFormat) {
            dataLength = "0" + dataLength;
        }

        strBuilder.insert(0, "##" + dataLength);

        strBuilder.append(crcStr + "\r\n");
        return strBuilder.toString();
    }

    @Override
    public int getInterval() {
        return interval;
    }

    @Override
    public String getName() {
        return "212心跳";
    }

    public static void main(String[] args) {
        BcSendPlatformModel platform = new BcSendPlatformModel();
        platform.setMn("TestLinRuiQiang");

        Heartbeat212 h212 = new Heartbeat212();
        String msg = h212.getData(platform);

        System.out.println(msg);

    }

}
